<template>
	<view class="page">
		<view class="form-content">
			<u-form :model="formData" ref="uForm" class="uForm" label-position="top">
				<u-form-item prop="data" label="日期" label-width="auto">
					<dateTime v-model="formData.data" :showLabel="false" :showArrow="false" :required="false"
						:disabled="true" className="new-date-picker" placeholder="请选择日期" jnpfKey="date">
					</dateTime>
				</u-form-item>
				<u-form-item prop="invoiceAmount" label="开票金额" label-width="auto">
					<u-input v-model="formData.invoiceAmount" placeholder="请输入开票金额" type="digit" />
					<view slot="right">万元</view>
				</u-form-item>
			</u-form>
		</view>
		<view class="save-bottom">
			<view class="fixed-btn save-padding">
				<u-button type="primary" shape="circle" @click="onSubmit">确定</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import dateTime from '@/components/dateTime/dateTime.vue'
	const apiUrl = "/api/Jiushi/Customeroperainfosale";
	export default {
		components: {
			dateTime
		},
		name: 'salesDetail',
		data() {
			return {
				formData: {
					id: undefined,
					customerId: undefined,
					data: undefined,
					invoiceAmount: undefined
				},
			}
		},
		onLoad(options) {
			if (options.cid) {
				this.formData.customerId = options.cid
			}
			if (options.id) {
				this.formData.id = options.id
				this.init()
			}
		},
		methods: {
			/* 初始化请求 */
			init() {
				this.$helper.ajax({
					url: apiUrl + "/" + this.formData.id,
					method: "GET",
					contentType: "application/json",
					success: res => {
						this.formData = res.data.data
					}
				});
			},
			/* 表单提交 */
			onSubmit() {
				let url = apiUrl;
				let method = "POST";
				if (this.formData.id) {
					url = url + "/" + this.formData.id;
					method = "PUT";
				}
				this.$helper.ajax({
					url: url,
					method: method,
					contentType: "application/json",
					data: this.formData,
					success: res => {
						this.$helper.msg('保存成功', 'success');
						uni.setStorage({
							key: "refreshPage",
							data: true
						})
						uni.navigateBack();
					}
				});
			},
		}
	}
</script>

<style>

</style>